# THIS SCRIPT CODES AND CLEANS DATA FROM THE ANES CUMULATIVE FILE. IT NEEDS TO BE 
# USED IN CONJUNCTION WITH THE FILE (AVAILABLE ON DATAVERSE) ENTITLED "ANES-2020.dta"
library(foreign)
library(car)
library(readstata13)
library(ggplot2)
library(stargazer)
library(grid)
library(gridExtra)
library(survey)
library(dplyr)
library(lemon)
library(ggpubr)
library(reshape2)
#-----
# READ IN THE DATA. SELECT THE FILE "ANES-2020.dta"
our.data = read.dta13(file.choose(), nonint.factors = TRUE,
                      generate.factors = TRUE)
#------
# WHITE, NON-HISPANIC
table(our.data$V201549x)
our.data$whiteNH = ifelse(our.data$V201549x=="1. White, non-Hispanic", 1, 0)
table(our.data$whiteNH, our.data$V201549x)
# 1 = WHITE, NON-HISPANIC; 0 = OTHER

# FEELING THERMOMETER, REPUBLICAN PARTY.
table(our.data$V201157)
levels(our.data$V201157)
our.data$repFT = our.data$V201157
levels(our.data$repFT)[c(1,64)] = c("Refused", "Dont Know")
levels(our.data$repFT)
our.data$repFT = car::recode(our.data$repFT, "'Refused' = NA;
                             'Dont Know' = NA")
our.data$repFT = as.numeric(as.character(our.data$repFT))
table(our.data$repFT, our.data$V201157)
table(our.data$repFT)

# FEELING THERMOMETER, DEMOCRATIC PARTY.
table(our.data$V201156)
levels(our.data$V201156)
our.data$demFT = our.data$V201156
levels(our.data$demFT)[c(1,67)] = c("Refused", "Dont Know")
levels(our.data$demFT)
our.data$demFT = car::recode(our.data$demFT, "'Refused' = NA;
                             'Dont Know' = NA")
our.data$demFT = as.numeric(as.character(our.data$demFT))
table(our.data$demFT)
table(our.data$V201156)
table(our.data$V201156, our.data$demFT)

# DIFFERENCE, REPUBLICAN FT - DEMOCRATIC FT 
our.data$repversusdemdiff_therm = our.data$repFT - our.data$demFT
summary(our.data$repversusdemdiff_therm)
our.data$repversusdemdiff_therm = scales::rescale(our.data$repversusdemdiff_therm)
table(our.data$repversusdemdiff_therm)

# PARTY ID
table(our.data$V201231x)
our.data$partyID = as.numeric(our.data$V201231x)
table(our.data$partyID)
our.data$partyID = car::recode(our.data$partyID, "1 = NA; 2 = NA")
our.data$partyID = our.data$partyID - 3
table(our.data$partyID, our.data$V201231x)
# 0 = STRONG DEMOCRAT; 6 = STRONG REPUBLICAN

# REPUBLICAN
our.data$republican = ifelse(our.data$partyID>=4 & our.data$partyID<=6, 1, 0)
table(our.data$republican, our.data$V201231x)
summary(our.data$republican)

# DEMOCRAT 
our.data$democrat = ifelse(our.data$partyID>=0 & our.data$partyID<=2, 1, 0)
table(our.data$democrat, our.data$V201231x)
summary(our.data$democrat)

# IDEOLOGICAL SELF-IDENTIFICATION
table(our.data$V201200)
our.data$ideology = as.numeric(our.data$V201200)
table(our.data$ideology)
our.data$ideology = car::recode(our.data$ideology, "10 = 6; 2 = 6; 1 = NA")
table(our.data$ideology)
our.data$ideology = our.data$ideology - 3
table(our.data$ideology, our.data$V201200)
# 0 = EXTREMELY LIBERAL; 6 = EXTREMELY CONSERVATIVE; 
# DK OR HTMA CODED AT MIDPOINT. 

# CONSERVATIVE 
our.data$conservative = ifelse(our.data$ideology>=4 & our.data$ideology<=6, 1, 0)
table(our.data$conservative, our.data$V201200)
summary(our.data$conservative)

# LIBERAL
our.data$liberal = ifelse(our.data$ideology>=0 & our.data$ideology<=2, 1, 0)
table(our.data$liberal, our.data$V201200)
summary(our.data$liberal)

# SORTED
our.data$sorted = rep(0, length(our.data$ideology))
our.data$sorted[our.data$republican==1 & our.data$conservative==1] = 1
table(our.data$sorted)
our.data$sorted[our.data$democrat==1 & our.data$liberal==1] = 1
table(our.data$sorted)
our.data$sorted[is.na(our.data$partyID)=="TRUE" | is.na(our.data$ideology)=="TRUE"] = NA
table(our.data$sorted)
table(our.data$sorted[our.data$republican==1], our.data$ideology[our.data$republican==1])
table(our.data$sorted[our.data$democrat==1], our.data$ideology[our.data$democrat==1])
# 1 = CONSERVATIVE REPUBLICAN OR LIBERAL DEMOCRAT (SELF-IDENTIFIED); 0 = ALL OTHERS

# IDEOLOGICAL PLACEMENT, DEMOCRATIC PARTY
table(our.data$V201206)
our.data$demplacement = as.numeric(our.data$V201206)
table(our.data$demplacement)
our.data$demplacement = car::recode(our.data$demplacement, "1 = NA; 2 = NA")
our.data$demplacement = our.data$demplacement - 3
table(our.data$demplacement, our.data$V201206)
# 0 = EXTREMELY LIBERAL; 6 = EXTREMELY CONSERVATIVE 

# IDEOLOGICAL PLACEMENT, REPUBLICAN PARTY 
table(our.data$V201207)
our.data$GOPplacement = as.numeric(our.data$V201207)
table(our.data$GOPplacement)
our.data$GOPplacement = car::recode(our.data$GOPplacement, "1 = NA; 2 = NA")
our.data$GOPplacement = our.data$GOPplacement - 3
table(our.data$GOPplacement, our.data$V201207)
# 0 = EXTREMELY LIBERAL; 6 = EXTREMELY CONSERVATIVE

# KNOWS PARTIES' POLICY REPUTATIONS
our.data$knowsreputations = ifelse(our.data$GOPplacement > our.data$demplacement, 1, 0)
sum(table(our.data$knowsreputations))
# DK CODED AS NOT KNOWING POLICY REPUTATIONS
our.data$knowsreputations[our.data$V201207=="-8. Don't know"] = 0
table(our.data$knowsreputations)
our.data$knowsreputations[our.data$V201206=="-8. Don't know"] = 0
table(our.data$knowsreputations)
# 0 = DOESN'T KNOW THAT THE REPUBLICAN PARTY IS MORE CONSERVATIVE THAN THE DEMOCRATIC PARTY;
# 1 = KNOWS THAT THE REPUBLICAN PARTY IS MORE CONSERVATIVE THAN THE DEMOCRATIC PARTY. 

# PROGRAMMATIC INDEX
our.data$programmatic = rep(NA, length(our.data$ideology))
# NOT MATCHED
our.data$programmatic[our.data$sorted==0 & our.data$knowsreputations==0] = 0
table(our.data$programmatic)
# PARTIALLY MATCHED
our.data$programmatic[our.data$sorted==1 & our.data$knowsreputations==0] = 0.5
table(our.data$programmatic)
our.data$programmatic[our.data$sorted==0 & our.data$knowsreputations==1] = 0.5
table(our.data$programmatic)
# MATCHED
our.data$programmatic[our.data$sorted==1 & our.data$knowsreputations==1] = 1
table(our.data$programmatic)
summary(our.data$programmatic)
# 1 = MATCHED; 0.5 = PARTIALLY MATCHED; 0 = UNMATCHED 

# SEVEN-POINT SCALE: GOVERNMENT SERVICES AND SPENDING
table(our.data$V201246)
our.data$govspending = as.numeric(our.data$V201246)
table(our.data$govspending)
our.data$govspending = car::recode(our.data$govspending, "9 = 5; 1 = NA")
our.data$govspending = our.data$govspending - 3
our.data$govspending = abs(our.data$govspending - 6)
our.data$govspending = scales::rescale(our.data$govspending)
table(our.data$govspending, our.data$V201246)
# 0-6 SCALE, 0 = GOVERNMENT SHOULD PROVIDE MANY MORE SERVICES; 6 = GOVERNMENT SHOULD PROVIDE
# MANY FEWER SERVICES. 'HAVEN'T THOUGHT MUCH ABOUT THIS' AND 'DK' CODED AT THE MIDPOINT. 

# SEVEN-POINT SCALE: GOVERNMENT HEALTHCARE
table(our.data$V201252)
our.data$govhealth = as.numeric(our.data$V201252)
table(our.data$govhealth)
our.data$govhealth = car::recode(our.data$govhealth, "10 = 6; 1 = NA; 2 = 6")
our.data$govhealth = our.data$govhealth - 3
our.data$govhealth = scales::rescale(our.data$govhealth)
table(our.data$govhealth, our.data$V201252)
# 0-TO-6 SCALE; 0 = GOVERNMENT-RUN HEALTH INSURANCE; 6 = PRIVATE INSURANCE
# 'HAVEN'T THOUGHT MUCH ABOUT THIS' CODED AT THE MIDPOINT. 

# SEVEN-POINT SCALE: GOVERNMENT GUARANTEED JOBS 
table(our.data$V201255)
our.data$govjobs = as.numeric(our.data$V201255)
table(our.data$govjobs)
our.data$govjobs = car::recode(our.data$govjobs, "10 = 6; 1 = NA; 2 = 6")
our.data$govjobs = our.data$govjobs - 3
our.data$govjobs = scales::rescale(our.data$govjobs)
table(our.data$govjobs, our.data$V201255)
# 0-TO-6 SCALE, 0 = GOVERNMENT SHOULD SEE TO JOBS AND GOOD STANDARD OR LIVING; 6 = 
# GOVERNMENT SHOULD LET EACH GET AHEAD ON OWN. "HAVEN'T THOUGHT MUCH ABOUT THIS' AND 'DON'T KNOW' 
# CODED AT THE MIDPOINT. 

# ADDITIVE INDEX: GOVERNMENT CONSERVATISM
our.data$govconservatism = (our.data$govjobs + our.data$govhealth + our.data$govspending)/3
table(our.data$govconservatism)
our.data$govconservatism = scales::rescale(our.data$govconservatism)
table(our.data$govconservatism)

# POLITICAL KNOWLEDGE: YEARS SENATOR ELECTED
table(our.data$V201644)
our.data$senatorterm = our.data$V201644
levels(our.data$senatorterm)
levels(our.data$senatorterm)[1:2] = c("NA1", "NA2")
table(our.data$senatorterm)
our.data$senatorterm = car::recode(our.data$senatorterm, "'NA1' = NA; 'NA2' = NA")
table(our.data$senatorterm)
our.data$senatorterm = as.numeric(as.character(our.data$senatorterm))
table(our.data$senatorterm)
our.data$senatorterm = ifelse(our.data$senatorterm==6, 1, 0)
table(our.data$senatorterm, our.data$V201644)
# 1 = CORRECT; 0 = INCORRECT

# POLITICAL KNOWLEDGE: PROGRAM ON WHICH FEDERAL GOVERNMENT SPENDS THE LEAST
table(our.data$V201645)
our.data$foreignaid = our.data$V201645
our.data$foreignaid = as.numeric(our.data$foreignaid)
table(our.data$foreignaid)
our.data$foreignaid = car::recode(our.data$foreignaid, "1 = NA; 2 = NA; 3 = 1; else = 0")
table(our.data$foreignaid, our.data$V201645)
# 1 = CORRECT; 0 = INCORRECT

# POLITICAL KNOWLEDGE: PARTY WITH MOST MEMBERS IN HOUSE BEFORE ELECTION
table(our.data$V201646)
our.data$house = our.data$V201646
our.data$house = as.numeric(our.data$house)
table(our.data$house)
our.data$house = car::recode(our.data$house, "1 = NA; 2 = NA; 3 = 1; 4 = 0")
table(our.data$house, our.data$V201646)
# 1 = CORRECT; 0 = INCORRECT 

# POLITICAL KNOWLEDGE: PARTY WITH MOST MEMBERS IN SENATE BEFORE ELECTION
table(our.data$V201647)
our.data$senate = our.data$V201647
our.data$senate = as.numeric(our.data$senate)
table(our.data$senate)
our.data$senate = car::recode(our.data$senate, "1 = NA; 2 = NA; 3 = 0; 4 = 1")
table(our.data$senate, our.data$V201647)
# 1 = CORRECT; 0 = INCORRECT 

# POLITICAL KNOWLEDGE: ADDITIVE INDEX 
attach(our.data)
knowledge.matrix = data.frame(senatorterm, senate, house, foreignaid)
knowledge.matrix = as.matrix(knowledge.matrix)
head(knowledge.matrix)
our.data$politicalknowledge = rowSums(knowledge.matrix, na.rm = TRUE)
table(our.data$politicalknowledge)
summary(our.data$politicalknowledge)
detach(our.data)
# REFUSED ALL FOUR QUESTIONS; DROP THESE FOLKS. 
table(our.data$politicalknowledge)
our.data$politicalknowledge[is.na(our.data$senatorterm)=="TRUE" & 
                              is.na(our.data$senate)=="TRUE" & 
                              is.na(our.data$house)=="TRUE" & 
                              is.na(our.data$foreignaid)=="TRUE"] = NA
table(our.data$politicalknowledge)
summary(our.data$politicalknowledge)
our.data$politicalknowledge = scales::rescale(our.data$politicalknowledge)
table(our.data$politicalknowledge)
# 0-TO-1 INDEX, % OF ANSWERS THAT THEY GOT CORRECT. MISSING CASES ARE ONLY PEOPLE THAT DIDN'T ANSWER
# *ANY* OF THE FOUR QUESTIONS. 

# LOW-LEVEL ACTIVISM: TALK TO ANYONE ABOUT VOTING FOR/AGAINST CANDIDATE OR PARTY
table(our.data$V202009)
our.data$lla_1 = as.numeric(our.data$V202009)
table(our.data$lla_1)
our.data$lla_1 = car::recode(our.data$lla_1, "1 = NA; 2 = NA; 3 = NA; 5 = 1; 6 = 0")
table(our.data$lla_1, our.data$V202009)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: GO TO ANY (IN-PERSON) POLITICAL MEETINGS, RALLIES, SPEECHES, DINNERS
table(our.data$V202014)
our.data$lla_2a = as.numeric(our.data$V202014)
table(our.data$lla_2a)
our.data$lla_2a = car::recode(our.data$lla_2a, "1 = NA; 2 = NA; 3 = NA; 4 = 1; 5 = 0")
table(our.data$lla_2a, our.data$V202014)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: GO TO ANY ONLINE POLITICAL MEETINGS, RALLIES, SPEECHES, FUNDRAISERS
table(our.data$V202013)
our.data$lla_2b = as.numeric(our.data$V202013)
table(our.data$lla_2b)
our.data$lla_2b = car::recode(our.data$lla_2b, "1 = NA; 2 = NA; 3 = 1; 4 = 0")
table(our.data$lla_2b, our.data$V202013)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: ATTEND MEETINGS (IN-PERSON *OR* ONLINE)
our.data$lla_2 = ifelse((our.data$lla_2a==1 | our.data$lla_2b==1), 1, 0)
table(our.data$lla_2, our.data$V202013)
table(our.data$lla_2, our.data$V202014)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: WEAR CAMPAIGN BUTTON, POST SIGN, OR BUMPER STICKER
table(our.data$V202015)
our.data$lla_3 = as.numeric(our.data$V202015)
table(our.data$lla_3)
our.data$lla_3 = car::recode(our.data$lla_3, "1 = NA; 2 = NA; 3 = NA; 4 = 1; 5 = 0")
table(our.data$lla_3, our.data$V202015)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: DO ANY (OTHER) WORK FOR PARTY OR CANDIDATE
table(our.data$V202016)
our.data$lla_4 = as.numeric(our.data$V202016)
table(our.data$lla_4)
our.data$lla_4 = car::recode(our.data$lla_4, "1 = NA; 2 = NA; 3 = 1; 4 = 0")
table(our.data$lla_4, our.data$V202016)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: CONTRIBUTE MONEY TO INDIVIDUAL CANDIDATE RUNNING FOR OFFICE
table(our.data$V202017)
our.data$lla_5a = as.numeric(our.data$V202017)
table(our.data$lla_5a)
our.data$lla_5a = car::recode(our.data$lla_5a, "1 = NA; 2 = NA; 3 = 1; 4 = 0")
table(our.data$lla_5a, our.data$V202017)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: CONTRIBUTE MONEY TO POLITICAL PARTY
table(our.data$V202019)
our.data$lla_5b = as.numeric(our.data$V202019)
table(our.data$lla_5b)
our.data$lla_5b = car::recode(our.data$lla_5b, "1 = NA; 2 = NA; 3 = NA; 4 = NA; 5 = 1; 6 = 0")
table(our.data$lla_5b, our.data$V202019)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: CONTRIBUTE MONEY TO ANY OTHER GROUP THAT SUPPORTED OR OPPOSED CANDIDATES
table(our.data$V202021)
our.data$lla_5c = as.numeric(our.data$V202021)
table(our.data$lla_5c)
our.data$lla_5c = car::recode(our.data$lla_5c, "1 = NA; 2 = NA; 3 = NA; 4 = NA; 5 = 1; 6 = 0")
table(our.data$lla_5c, our.data$V202021)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: CONTRIBUTE MONEY (REGARDLESS OF RECIPIENT)
our.data$lla_5 = ifelse(our.data$lla_5a==1 | our.data$lla_5b==1 | our.data$lla_5c==1, 1, 0)
table(our.data$lla_5, our.data$V202021)
table(our.data$lla_5, our.data$V202019)
table(our.data$lla_5, our.data$V202017)
# 1 = YES; 0 = NO

# LOW-LEVEL ACTIVISM: ADDITIVE INDEX 
attach(our.data)
lla.data = data.frame(lla_1, lla_2, lla_3, lla_4, lla_5)
lla.data = as.matrix(lla.data)
head(lla.data)
our.data$llactivism = rowSums(lla.data, na.rm = TRUE)
summary(our.data$llactivism)
detach(our.data)
# DIDN'T ANSWER ANY OF THE QUESTIONS; DROP THESE PEOPLE.
table(our.data$llactivism)
our.data$llactivism[is.na(our.data$lla_1)=="TRUE" & 
                      is.na(our.data$lla_2a)=="TRUE" &
                      is.na(our.data$lla_2b)=="TRUE" &
                      is.na(our.data$lla_3)=="TRUE" & 
                      is.na(our.data$lla_4)=="TRUE" & 
                      is.na(our.data$lla_5a)=="TRUE" & 
                      is.na(our.data$lla_5b)=="TRUE" & 
                      is.na(our.data$lla_5c)=="TRUE"] = NA
table(our.data$llactivism)
summary(our.data$llactivism)
our.data$llactivism = scales::rescale(our.data$llactivism)
table(our.data$llactivism)
# ADDITIVE INDEX, RESCALED BETWEEN 0-1. THE MISSING CASES ARE PEOPLE THAT DIDN'T ANSWER *ANY* OF 
# THE LOW-LEVEL ACTIVISM QUESTIONS (EITHER BECAUSE THEY SKIPPED THEM ALL OR DIDN'T TAKE THE 
# POST-ELECTION SURVEY)

# EDUCATIONAL ATTAINMENT (CONTINUOUS VARIABLE)
table(our.data$V201510)
our.data$education = as.numeric(our.data$V201510)
table(our.data$education)
our.data$education = car::recode(our.data$education, 
                                 "1 = NA; 2 = NA; 3 = 0; 4 = 1; 5 = 2; 6 = 3; 7 = 3; 8 = 4; 9 = 5; 10 = 5; 11 = NA")
table(our.data$education, our.data$V201510)
our.data$education = scales::rescale(our.data$education)
table(our.data$education)
# 0 = LESS THAN HIGH SCHOOL; 1 = HIGH SCHOOL OR EQUIVALENCY; 2 = SOME COLLEGE; 
# 3 = TWO-YEAR DEGREE; 4 = FOUR-YEAR DEGREE; 5 = POST-GRADUATE DEGREE

# INTEREST IN FOLLOWING CAMPAIGNS
table(our.data$V201006)
our.data$interest.campaigns = as.numeric(our.data$V201006)
table(our.data$interest.campaigns)
our.data$interest.campaigns = car::recode(our.data$interest.campaigns, "1 = NA; 2 = 1; 3 = 0.5; 4 = 0")
table(our.data$interest.campaigns, our.data$V201006)
our.data$interest.campaigns = scales::rescale(our.data$interest.campaigns)
table(our.data$interest.campaigns, our.data$V201006)
# 0 = NOT MUCH INTERESTED; 0.5 = SOMEWHAT INTERESTED; 1 = VERY INTERESTED

# HOW OFTEN DOES RESPONDENT FOLLOW CURRENT AFFAIRS
table(our.data$V201005)
our.data$newsinterest = as.numeric(our.data$V201005)
table(our.data$newsinterest)
our.data$newsinterest = car::recode(our.data$newsinterest, "1 = NA; 2 = 4; 3 = 3; 4 = 2; 5 = 1; 6 = 0; else = NA")
table(our.data$newsinterest)
our.data$newsinterest = scales::rescale(our.data$newsinterest)
table(our.data$newsinterest, our.data$V201005)
# 0 = NEVER; 1 = SOME OF THE TIME; 2 = ABOUT HALF THE TIME; 3 = MOST OF THE TIME; 4 = ALWAYS 
# (NOTE CHANGE IN RESPONSE OPTIONS COMPARED TO 1988)

# INTEREST IN POLITICS (ADDITIVE INDEX)
our.data$interest.politics = (our.data$newsinterest + our.data$interest.campaigns)/2
table(our.data$interest.politics)

# AID TO BLACKS
table(our.data$V201258)
our.data$aidtoblacks = as.numeric(our.data$V201258)
table(our.data$aidtoblacks)
our.data$aidtoblacks = car::recode(our.data$aidtoblacks, "1 = NA; 2 = 6; 10 = 6")
table(our.data$aidtoblacks)
our.data$aidtoblacks = our.data$aidtoblacks - 3
our.data$aidtoblacks = scales::rescale(our.data$aidtoblacks)
table(our.data$aidtoblacks, our.data$V201258)
# 0 = GOVERNMENT SHOULD HELP BLACKS; 6 = GOVERNMENT SHOULD HELP THEMSELVES.
# 'HAVEN'T THOUGHT MUCH ABOUT THIS' RECODED AT THE MIDPOINT. 

# AFFIRMATIVE ACTION, ATTITUDES (PREFERENTIAL HIRING OR PROMOTION OF BLACKS)
table(our.data$V202252x)
our.data$affirmativeaction = car::recode(as.numeric(our.data$V202252x), 
                                         "1 = NA; 2 = NA; 3 = NA; 4 = NA") - 5
table(our.data$affirmativeaction, our.data$V202252x)
our.data$affirmativeaction = scales::rescale(our.data$affirmativeaction)
table(our.data$affirmativeaction, our.data$V202252x)
# 0 = STRONGLY FOR PREFERENTIAL HIRING/PROMOTION OF BLACKS; 3 = STRONGLY AGAINST
# PREFERENTIAL HIRING/PROMOTION

# THE WORLD IS ALWAYS CHANGING AND WE SHOULD ADJUST OUR VIEW OF MORAL BEHAVIOR
our.data$adjustmoralviews = our.data$V202264 
table(our.data$adjustmoralviews)
our.data$adjustmoralviews = car::recode(as.numeric(our.data$adjustmoralviews), 
                                        "1 = NA; 2 = 8; 3 = NA; 4 = NA; 5 = NA") - 6
table(our.data$adjustmoralviews, our.data$V202264)
# 0 = AGREE STRONGLY; 4 = DISAGREE STRONGLY; DON'T KNOW CODED AT THE MIDPOINT 

# THIS COUNTRY WOULD HAVE MANY FEWER PROBLEMS IF THERE WERE MORE EMPHASIS ON TRADITIONAL FAMILY VALUES.
our.data$familyties = our.data$V202265 
table(our.data$familyties)
our.data$familyties = car::recode(as.numeric(our.data$familyties), "1 = NA; 2 = 8; 3 = NA; 4 = NA; 5 = NA") - 6
our.data$familyties = abs(our.data$familyties - 4)
table(our.data$familyties, our.data$V202265)
# 0 = DISAGREE STRONGLY; 4 = AGREE STRONGLY; DON'T KNOW CODED AT THE MIDPOINT 

# TRADITIONAL VALUES
our.data$tradvalues = (our.data$familyties + our.data$adjustmoralviews)/2
our.data$tradvalues = scales::rescale(our.data$tradvalues)
summary(our.data$tradvalues)

# RACIAL ATTITUDES
our.data$racial = (our.data$aidtoblacks + our.data$affirmativeaction)/2
summary(our.data$racial)
#-----
# DROP INDEPENDENTS FROM THE DATASET
new.data = subset(our.data, republican==1 | democrat==1)
#----
# SAVE DATASET 
# write.csv(our.data, file = "ANES2020_cleaned+inds.csv")
# write.csv(new.data, file = "ANES2020_cleaned.csv")

